// std functions
#include <iostream>
#include <stdexcept>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>

// boost functions
#include <boost/program_options.hpp>

// my functions
#include <print_error.h>
#include <program_options_helper.h>
#include <stlhelper.h>
#define DEBUG_LEVEL 6
#include <debug_func.h>
#include <blast_results.h>
#include "get_arg.h"
using std::string;
using std::cerr;
using std::cout;
using std::max;
using std::vector;



// link with -lboost_filesystem-gcc -lboost_program_options-gcc
// program_options_helper.cpp
//-lboost_filesystem-gcc-d
//-L/usr/local/lib

using namespace program_options_helper;
namespace po = boost::program_options_lg;


//_______________________________________________________________________________________

//		process_command_line_options

//				from command line
//				Created [9/13/2001]

//_______________________________________________________________________________________
bool process_command_line_options(int argc, char* argv[], t_program_args& args)
{

	//
	// checked mandatory arguments
	//
	po::options_description mandatory_args("Mandatory Arguments");
	mandatory_args.add_options()
	("window_size,w", 		po::value<unsigned>(&args.windows_size)
								->set_name("NUMBER"),
								"GC is calculated in these sizes.")
	("results_path,r", 		po::value<string>(&args.results_path)
								->set_name("PATH"),
								"Generates the output file name.");

	po::options_description hidden_args("Hidden Arguments");
	hidden_args.add_options()
	("input_files,i", 		po::value<vector<string> >(&args.input_files),
								"Input files.");



	args.optional_args.add_options()
	("detail_errors,d", po::bool_switch(&args.detail_errors),
							"Report errors in detail\n");





	args.add_std_options();
	po::options_description all_args("");                              
	all_args.add(hidden_args)
			.add(args.optional_args)
			.add(mandatory_args);

	// positional arguments
	po::positional_options_description p;
	p.add("input_files", -1);

	// parse command line
	po::variables_map vm;
	po::store(po::command_line_parser(argc, argv).options(all_args).positional(p).run(), vm);
	po::notify(vm);

	if (vm.count("version"))
	{
		print_version(cerr, *argv, "1.0\n"
			"\tHistory: \n\n"
			"\tv 1.0\1"
			"1-10-2006\1"
			"Initial version\n"
			);
		return false;
	}

	if (vm.count("help"))
	{
		string exe_description =
								"Calculate GC Content across a supplied file. Results are printed in "
								"tab-delimited columns: Position from sequence start<TAB> "
								"Position from sequence end <TAB> GC.\n"
								"Only prints out results from regions with [ACGTacgt]\n"
								"Assumes that each file contains a single chromosome/sequence "
								"with an optional FASTA header.\n"
								"The results are placed into files generated from --results_path."
								"If you are analysing > 1 file, enter a wild card to generate a "
								"different result file for each input file using "
								"\"[PATH][FILENAME][EXT]\".\n"
								"E.g.\n"
								"Input files = \n"
								"    \"\\my_dir\\here\\chr1.fa\"\n"
								"    \"\\my_dir\\here\\chr2\"\n"
								"--results_path = \"[PATH]results_[FILENAME]_done[EXT]\n"
								"Output files = \n"
								"    \"\\my_dir\\here\\results_chr1_done.fa\"\n"
								"    \"\\my_dir\\here\\results_chr2_done\"\n";
		po::options_description visible_args("");                              
		visible_args
					.add(args.optional_args)
					.add(mandatory_args);
		print_usage(cerr, string(*argv), "[OPTIONS] --input_files SEQUENCE1 SEQUENCE2",
							all_args, exe_description, 80);
		return false;
	}
	//check_required_options(vm, mandatory_args);

	args.open_err_log();
	return true;
}

